using GameFramework.Event;
using UnityEngine;
using UnityGameFramework.Runtime;

namespace StarForce
{
    public class WatermelonGame : GameBase
    {
        public override GameMode GameMode
        {
            get { return GameMode.Watermelon; }
        }

        private Watermelon m_CurWatermelon
        {
            get { return (Watermelon)GameEntry.Entity.GetEntity(m_CurWatermelonId).Logic; }
        }

        private int m_CurWatermelonId;

        public int CurWatermelonId
        {
            get { return m_CurWatermelonId; }
            set { m_CurWatermelonId = value; }
        }

        public override void Initialize()
        {
            base.Initialize();

            GameEntry.UI.OpenUIForm(UIFormId.WatermelonMainPage, this);

            WatermelonManager.Instance.SetWatermelonGame(this);
            
            WatermelonManager.Instance.CreateRandomWaterMelon(0,false);
            
            
        }

        public override void Update(float elapseSeconds, float realElapseSeconds)
        {
            base.Update(elapseSeconds, realElapseSeconds);

            if (Input.GetMouseButtonDown(0))
            {
//                Log.Info("aaaaaaaaaa");
                Vector3 v = Input.mousePosition;
                v.z = 10f;
                
                Vector3 touchDeltaPosition = GameEntry.UI.UICamera.ScreenToWorldPoint(v);
                
                Log.Info("--:"+touchDeltaPosition.x);
                
//                WatermelonManager.Instance.CreateRandomWaterMelon(touchDeltaPosition.x,false);

                m_CurWatermelon.Move(touchDeltaPosition.x);
            }

//            if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
//            {
//                Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
//               
//                m_WatermelonManager.CreateRandomWaterMelon(touchDeltaPosition.x);
//            }
        }

//        protected override void OnShowEntitySuccess(object sender, GameEventArgs e)
//        {
//            base.OnShowEntitySuccess(sender, e);
//
//            ShowEntitySuccessEventArgs result = (ShowEntitySuccessEventArgs) e;
//            m_CurWatermelon = (Watermelon) result.Entity.Logic;
//
//        }
    }
}